/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controladores;

import DAO.DAO_Movie;
import DAO.DAO_Person;
import DAO.DAO_Song;
import DAO.DAO_Soundtrack;
import Entidad.*;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author lleyzzon
 */
public class ControladorRegistros {
    
    DAO_Movie dao_movie = new DAO_Movie();
    DAO_Person dao_person = new DAO_Person();
    DAO_Song dao_song = new DAO_Song();
    DAO_Soundtrack dao_soundtrack = new DAO_Soundtrack();
    
    public static EntityManagerFactory ef;
    public static EntityManager em;
    
     public ControladorRegistros () {
        ef = Persistence.createEntityManagerFactory("GRLU-GPU", System.getProperties());
        em = ef.createEntityManager();
     }
     
     /*
      * Esta funcion registra una nueva pelicula reciviendo como parametros los siguientes datos:
      * name, year, cover, plotKeyWords, Genre, Rating Duration.
      */
     
     public String RegistrarPelicula(String name, Integer year, String cover, String plotKeyWords, String Genre, Float rating, Float duration, Boolean rental, Boolean purchase){
         
         Movie new_movie = new Movie(name, year, cover, plotKeyWords, Genre, rating, duration, rental, null, null, null, purchase);
                  
         String mensaje1;
         mensaje1 = dao_movie.create(new_movie, em);
         
         return mensaje1;
     }
     
     /*
      * Esta funcion registra una nueva persona reciviendo como parametros los siguientes datos:
      * type, name, lastname, picture, birthdate y birthplace. De acuerdo al type que recive la funcion
      * decide que tipo de persona registrar.
      */
     
     public String RegistrarPerson(String type, String name, String lastname, String picture, String birthdate, String birthplace){
         Person new_person = new Person();
         String mensaje = null;
         
         new_person.setName(name);
         new_person.setLastName(lastname);
         new_person.setPicture(picture);
         new_person.setBirthdate(birthdate);
         new_person.setBirthplace(birthplace);
         
         
         switch(type){
             
             case "director":
                 Director director = new Director();
                 director.setName(new_person.getName());
                 director.setLastName(new_person.getLastName());
                 director.setPicture(new_person.getPicture());
                 director.setBirthdate(new_person.getBirthdate());
                 director.setBirthplace(new_person.getBirthplace());
                 
                 mensaje = dao_person.create(director, em);
                 break;
                 
             case "actor":
                 Actor actor = new Actor();
                 
                 actor.setName(new_person.getName());
                 actor.setLastName(new_person.getLastName());
                 actor.setPicture(new_person.getPicture());
                 actor.setBirthdate(new_person.getBirthdate());
                 actor.setBirthplace(new_person.getBirthplace());
                 
                 mensaje = dao_person.create(actor, em);
                 break;
                 
             case "artist":
                 Artist artist = new Artist();
                 
                 artist.setName(new_person.getName());
                 artist.setLastName(new_person.getLastName());
                 artist.setPicture(new_person.getPicture());
                 artist.setBirthdate(new_person.getBirthdate());
                 artist.setBirthplace(new_person.getBirthplace());
                 
                 mensaje = dao_person.create(artist, em);
                 break;
         }
       
         return mensaje;
         
     }
     
     public String RegistrarSong(String tittle, Float duration){
         
         Song song = new Song(tittle, duration, null, null);
         String mensaje;
         
         mensaje = dao_song.create(song, em);
         
         return mensaje;
     }
     
     public String RegistrarSoundtrack(String picture){
         
         Soundtrack soundtrack = new Soundtrack(picture, null, null);
         String mensaje;
         
         mensaje = dao_soundtrack.create(soundtrack, em);
         
         return mensaje;
     }
    
}
